<?php

/**
 * As we have first renderer, lets work on orm 
 * which is quite essential at the moment..
 * 
 * uhh, many things to finish, and time is quite less.
 * 
 * 
 *  
 */
class orm {

    public $config = array();

    public function __construct($config) {
        $this->config = $config;
    }

    public function process() {
        if (empty($this->config)) {
            throw new Exception("Form config not set. ");
        }
        $controls = explode(",",$this->config['controls']);
        foreach($controls as $each_control){
            $this->elements[] = $this->renderElement($each_control);
        }
    }

    public function renderElement($type){
        $return = '';
        switch($type){
            case 'text':
                $return = "<input type='text' />";
                break;
            case "password":
                $return = "<input type='password' />";
                break;
            case "submit":
                $return = "<input type='submit' />";
            break;
            default:
                throw new Exception("ORM element renderer not found. Element : {$type}");
        }
        return $return;
    }

    public function doFinalRender(){
       $out = out::__s();
       $out->finalOutput[] =  "<form >".implode("",$this->elements)."</form>";
       
    }
    public function renderForm() {
        $this->process();
        $this->doFinalRender();
    }

}

?>